import 'package:flutter/material.dart';
import 'common.dart';

Widget buildDialog(BuildContext context) {
  return AlertDialog(
    title: const Text('标题'),
    content: SingleChildScrollView(
      child: ListBody(
        children: const <Widget>[
          Text('内容 1'),
          Text('内容 2'),
        ],
      ),
    ),
    actions: <Widget>[
      ElevatedButton(
        child: const Text('确定'),
        onPressed: () => Navigator.of(context).pop('dialog result'),
      ),
    ],
  );
}

Widget buildErrorDialog(BuildContext context) {
  generateError();
  return buildDialog(context);
}

Widget buildEntryButton(
  BuildContext context,
  String text,
  String url, {
  Object? arguments,
}) {
  return buildButton(
    context,
    text,
    () => Navigator.of(context).pushNamed(url, arguments: arguments),
  );
}

Widget buildButton(BuildContext context, String text, VoidCallback onPressed) {
  final TextStyle buttonTextStyle = Theme.of(context).textTheme.button ?? DefaultTextStyle.of(context).style;
  return Padding(
    padding: const EdgeInsets.only(
      top: 10,
      bottom: 10,
    ),
    child: SizedBox(
      width: double.infinity,
      child: ElevatedButton(
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Text(
            text,
            style: buttonTextStyle.copyWith(
              color: Colors.white,
              fontSize: 18,
            ),
          ),
        ),
        onPressed: onPressed,
      ),
    ),
  );
}

Widget buildListItem(int index) {
  return Padding(
    padding: const EdgeInsets.only(
      top: 8,
      bottom: 8,
    ),
    child: Row(
      children: <Widget>[
        _buildRowItem(index * 2),
        _buildRowItem(index * 2 + 1),
      ],
    ),
  );
}

Widget _buildRowItem(int index) {
  return Expanded(
    child: Padding(
      padding: const EdgeInsets.only(
        left: 4,
        right: 4,
      ),
      child: Container(
        height: 60.0,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(6),
          color: const Color(0xFFE5E5E5),
        ),
        child: Center(
          child: Text(
            'Test Item $index',
            style: const TextStyle(
              fontSize: 26.0,
            ),
          ),
        ),
      ),
    ),
  );
}
